﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using com.pro2e.console.service.auth.vo;
using com.pro2e.console.core.valueobject;
using System.Collections.Generic;
using NHibernate;

/// <summary>
/// MenuFuncDao 的摘要描述
/// </summary>
/// 
namespace com.pro2e.console.service.auth.dao
{
    public class MenuFuncDao : DaoImp
    {
        public MenuFuncDao()
        {

        }

        /// <summary>
        /// 取出為第一層的MenuFunc
        /// </summary>
        /// <returns></returns>
        public IList<MenuFunc> GetTopMenuFuncList()
        {
            IQuery query = GetHBNSession().CreateQuery("From MenuFunc order by ListOrder");

            var result = from data in query.List<MenuFunc>()
                         where data.ParentMenu == null
                         select data;
                       
            return ( result.ToList<MenuFunc>());
        }

        /// <summary>
        /// 取出不為第一層的MenuFunc
        /// </summary>
        /// <returns></returns>
        internal IList<MenuFunc> GetNotTopMenuFunc()
        {
            IQuery query = GetHBNSession().CreateQuery("From MenuFunc order by ParentId,ListOrder");

            var result = from data in query.List<MenuFunc>()
                         where data.ParentMenu != null
                         select data;

            return (result.ToList<MenuFunc>());
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        internal IList<MenuFunc> GetMenuFuncByParentId(int p)
        {
            IQuery query = GetHBNSession().CreateQuery("From MenuFunc m where m.ParentMenu.Id = :Id order by ListOrder");
            query.SetInt32("Id", p);
            return(query.List<MenuFunc>());            
        }
    }
}